import json

file_name = 'ai.json'



# 需要的企业信息
def get_basic_info():
    # 打开文件并加载内容
    with open(file_name, 'r', encoding='utf8') as file:
        data = json.load(file)

    # 基本信息提取
    basic_info = data["eachEnterpriseBasicVo"]["infoVo"]
    enterpriseName = data["eachEnterpriseBasicVo"]["infoVo"]['enterpriseName']
    industry_name = basic_info.get("industryName", "暂无数据")
    company_translation = basic_info.get("companyTranslation", "暂无数据")
    business_products = basic_info.get("businessProducts", "暂无数据")
    customer = basic_info.get("customer", "暂无数据") or "暂无数据"

    # 财务信息提取（取最新年份数据）
    financial_info = max(
        data["enterprisePersonnelFinanceVo"]["financialInfoVos"],
        key=lambda x: x["timeYear"]
    )
    net_profit = financial_info["netProfit"]
    operating_income = financial_info["operatingIncome"]
    operating_costs = financial_info["operatingCosts"]
    pay_taxes = financial_info["payTaxes"]
    total_industrial = financial_info["totalIndustrial"]
    time_year = financial_info["timeYear"]

    # 投资情况提取（列出所有资助记录）
    subsidies = data["entSubsidizeSituationList"]
    subsidy_details = []
    for i, subsidy in enumerate(subsidies, 1):
        subsidy_details.append(f"""
            {i}.
            政府资助金额（万元）：{subsidy["awardAmt"]}
            资助部门：{subsidy["awardDept"]}
            最近资助时间：{subsidy["createTime"]}
            """)

    subsidy_details_str = "".join(subsidy_details) if subsidies else "无"

    # 就业信息提取
    personnel = data["enterprisePersonnelFinanceVo"]["personnelInfoVo"]
    staff_total = personnel["staffTotal"]
    social_security = personnel["socialSecurityTotal"]
    bachelor_total = personnel["bachelorTotal"]
    college_graduates = personnel["collegeGraduates"]

    # 风险信息提取
    risk = data['riskVo']
    completableFuture1 = risk['completableFuture1']['records']
    completableFuture2 = risk['completableFuture2']['records']
    completableFuture3 = risk['completableFuture3']['records']
    completableFuture5 = risk['completableFuture5']['records']
    completableFuture6 = risk['completableFuture6']['records']
    completableFuture7 = risk['completableFuture7']['records']

    return {
        'enterpriseName': enterpriseName,
        'industry_name': industry_name,
        'company_translation': company_translation,
        'business_products': business_products,
        'customer': customer,
        'net_profit': net_profit,
        'operating_income': operating_income,
        'operating_costs': operating_costs,
        'pay_taxes': pay_taxes,
        'total_industrial': total_industrial,
        'time_year': time_year,
        'subsidy_details_str': subsidy_details_str,
        'staff_total': staff_total,
        'social_security': social_security,
        'bachelor_total': bachelor_total,
        'college_graduates': college_graduates,
        'completableFuture1': completableFuture1,
        'completableFuture2': completableFuture2,
        'completableFuture3': completableFuture3,
        'completableFuture5': completableFuture5,
        'completableFuture6': completableFuture6,
        'completableFuture7': completableFuture7
    }

